﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ContinuousMacro.CApCMContinuousMacroDisplayer
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.DataTypes;


namespace DnProcessSimulateCommands.ContinuousMacro;

internal class CApCMContinuousMacroDisplayer : CApCMGraphicsShapeDisplayer<CApCMMacroShape>
{
  public new ITxDisplayableObject DisplayShape => base.DisplayShape;

  public CApCMContinuousMacroDisplayer(
    TxRoboticViaLocationOperation viaLocation,
    TxComponent displayParent,
    CApCMMacroShape macroShape = null)
    : base(viaLocation, displayParent, macroShape)
  {
    this.IsRecreatedOnAbsoluteLocationChanged = false;
  }

  protected override void SetAbsoluteLocation()
  {
    if (this.DisplayShape == null)
      return;
    double[] parameters = this.CreationData.Parameters;
    switch (this.CreationData.Shape)
    {
      case CApCMShape.Circle:
        (this.DisplayShape as ITxLocatableObject).AbsoluteLocation = this.ViaLocation.AbsoluteLocation;
        break;
      case CApCMShape.Slot:
        (this.DisplayShape as ITxLocatableObject).AbsoluteLocation = TxTransformation.op_Multiply(this.ViaLocation.AbsoluteLocation, new TxTransformation(new TxVector(0.0, parameters[1], 0.0), (TxTransformation.TxTransformationType) 1));
        break;
      case CApCMShape.Rectangle:
        (this.DisplayShape as ITxLocatableObject).AbsoluteLocation = TxTransformation.op_Multiply(this.ViaLocation.AbsoluteLocation, new TxTransformation(new TxVector(0.0, parameters[1] / 2.0, 0.0), (TxTransformation.TxTransformationType) 1));
        break;
      default:
        throw new NotImplementedException($"Displaying shape of type {this.CreationData.Shape.ToString()} is not implemented.");
    }
  }

  protected override ITxDisplayableObject CreateShape()
  {
    double[] parameters = this.CreationData.Parameters;
    ITxDisplayableObject shape;
    switch (this.CreationData.Shape)
    {
      case CApCMShape.Circle:
        TxCircleCreationData circleCreationData = new TxCircleCreationData("", new TxVector(0.0, 0.0, 0.0), new TxVector(0.0, 0.0, -1.0), parameters[0]);
        ((TxLocatableObjectCreationData) circleCreationData).AbsoluteLocation = this.ViaLocation.AbsoluteLocation;
        circleCreationData.SetAsDisplay();
        shape = (ITxDisplayableObject) ((TxBaseGeometryCreationObject) this.DisplayParent).CreateCircle(circleCreationData);
        break;
      case CApCMShape.Slot:
        TxSlotCreationData slotCreationData = new TxSlotCreationData("", parameters[0], parameters[1] * 2.0);
        TxTransformation txTransformation1 = new TxTransformation(new TxVector(0.0, parameters[1], 0.0), (TxTransformation.TxTransformationType) 1);
        ((TxLocatableObjectCreationData) slotCreationData).AbsoluteLocation = TxTransformation.op_Multiply(this.ViaLocation.AbsoluteLocation, txTransformation1);
        slotCreationData.SetAsDisplay();
        shape = ((TxBaseGeometryCreationObject) this.DisplayParent).CreateSlot(slotCreationData) as ITxDisplayableObject;
        break;
      case CApCMShape.Rectangle:
        TxRectangleCreationData rectangleCreationData = new TxRectangleCreationData("", parameters[0], parameters[1]);
        TxTransformation txTransformation2 = new TxTransformation(new TxVector(0.0, parameters[1] / 2.0, 0.0), (TxTransformation.TxTransformationType) 1);
        ((TxLocatableObjectCreationData) rectangleCreationData).AbsoluteLocation = TxTransformation.op_Multiply(this.ViaLocation.AbsoluteLocation, txTransformation2);
        rectangleCreationData.SetAsDisplay();
        shape = ((TxBaseGeometryCreationObject) this.DisplayParent).CreateRectangle(rectangleCreationData) as ITxDisplayableObject;
        break;
      default:
        throw new NotImplementedException($"Displaying shape of type {this.CreationData.Shape.ToString()} is not implemented.");
    }
    shape.Color = TxColor.TxColorBlue;
    TxDisplayableObjectEx.SetSelectable(shape, false);
    return shape;
  }
}
